package com.example.jianzhioffer;

/**
 * Created by Quincy on 2018/9/12.
 * 输入两个单调递增的链表，输出两个链表合成后的链表，当然我们需要合成后的链表满足单调不减规则
 */
public class MergeList {
    public class ListNode{
        int val;
        ListNode next = null;
        ListNode(int val){
            this.val = val;
        }
    }
    public static ListNode merge(ListNode node1, ListNode node2){
        if (node1 == null) return node2;
        if (node2 == null) return node1;
        ListNode node = null;
        if (node1.val < node2.val){
            node = node1;
            node.next = merge(node1.next, node2);
        }else {
            node = node2;
            node.next = merge(node1, node2.next);
        }
        return node;
    }
}
